﻿using HlELock.Core;
using HlELock.Core.Events;
using HlELock.Modules.Hotel.Main.Views;
using Prism.Commands;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

namespace HlELock.Modules.Hotel.Main.ViewModels
{
    /// <summary>
    /// 卡片管理
    /// </summary>
    public class SendOtherCardUserControlViewModel : BindableBase
    {
        public SendOtherCardUserControlViewModel()
        {

        }

        private DelegateCommand<string> _sendCardCommand;
        public DelegateCommand<string> SendCardCommand =>
            _sendCardCommand ?? (_sendCardCommand = new DelegateCommand<string>(ExecuteSendCardCommand));

        void ExecuteSendCardCommand(string t)
        {
            var descr = AppHelper.GetResourceString("ChengGong");
            switch (t)
            {
                //授权卡
                case "0":
                    if (MyAppContext.Device.SendAuthorizeCard())
                    {
                        MessageBox.Show(descr);
                    }
                    break;
                //时间卡
                case "1":
                    if (MyAppContext.Device.SendTimeCard())
                    {
                        MessageBox.Show(descr);
                    }
                    break;
                //记录卡
                case "2":
                    if (MyAppContext.Device.SendRecordCard())
                    {
                        MessageBox.Show(descr);
                    }
                    break;
                //清除卡(工厂清除卡）
                case "3":
                    if (MyAppContext.IsSf)
                    {
                        SfHelper.Instance.CancelGuestCard();
                    }
                    else
                    {
                        //if (MyAppContext.Device.SendFactoryTestCard()==Result)
                        //{
                        //    MessageBox.Show(descr);
                        //}
                    }
                    break;
                //读取卡片
                case "4":
                    var card = MyAppContext.CardService.ReadCard();
                    if (card != null)
                    {
                        EventBus.ShowDialogWindow(new DialogWindowEventArgs
                        {
                            Parameters = new Dictionary<string, object>
                                     {
                                     {nameof(CardDetailInfo),card }
                                     },
                            Title = AppHelper.GetResourceString("KaPianXingXi"),
                            Uri = nameof(CardInfoUserControl)
                        });
                    }
                    else
                    {
                        MessageBox.Show(AppHelper.GetResourceString("MeiYouDuQuDaoRenHeXingXi"));
                    }
                    break;
                //经销商测试卡
                case "5":
                    if (MyAppContext.Device.SendAgencyTestCard())
                    {
                        MessageBox.Show(descr);
                    }
                    break;
                default:
                    break;
            }

        }
    }
}
